import request from '@/utils/request'

/**
 * 查询参数配置列表
 */
export function getConfigList(query?: any) {
  return request.get('/system/config/list', query)
}

/**
 * 查询参数配置详细
 */
export function getConfig(configId: number) {
  return request.get(`/system/config/${configId}`)
}

/**
 * 根据参数键名查询参数值
 */
export function getConfigKey(configKey: string) {
  return request.get(`/system/config/configKey/${configKey}`)
}

/**
 * 新增参数配置
 */
export function addConfig(data: any) {
  return request.post('/system/config', data, {
    showLoading: true,
    showSuccess: true,
    successMsg: '参数配置新增成功',
  })
}

/**
 * 修改参数配置
 */
export function updateConfig(data: any) {
  return request.put('/system/config', data, {
    showLoading: true,
    showSuccess: true,
    successMsg: '参数配置修改成功',
  })
}

/**
 * 删除参数配置
 */
export function delConfig(configIds: number | number[]) {
  const ids = Array.isArray(configIds) ? configIds.join(',') : configIds
  return request.delete(`/system/config/${ids}`, {}, {
    showLoading: true,
    showSuccess: true,
    successMsg: '参数配置删除成功',
  })
}

/**
 * 导出参数配置
 */
export function exportConfig(query?: any) {
  return request.post('/system/config/export', query, {
    responseType: 'blob',
    showLoading: true,
  })
}

/**
 * 刷新参数缓存
 */
export function refreshCache() {
  return request.delete('/system/config/refreshCache', {}, {
    showLoading: true,
    showSuccess: true,
    successMsg: '刷新缓存成功',
  })
}

